package com.bytedance.lucky.error;

/**
 * 业务统一异常
 *
 * @author zouyaowen
 * @date 2021-02-12 21:22
 */
public class ServiceException extends RuntimeException implements CommonError {
    private ExceptionEnum exceptionEnum;
    /**
     * 状态码
     */
    private Integer status;
    /**
     * 异常信息
     */
    private String message;

    public Integer getStatus() {
        return this.exceptionEnum.getStatus();
    }

    public ServiceException(ExceptionEnum exceptionEnum) {
        this.exceptionEnum = exceptionEnum;
    }

    public ServiceException(ExceptionEnum exceptionEnum, String message) {
        this.exceptionEnum = exceptionEnum;
        this.exceptionEnum.setErrorMessage(message);
    }

    public ServiceException(Integer status, String message) {
        this.status = status;
        this.message = message;
    }

    @Override
    public String getMessage() {
        return getErrorMessage();
    }

    @Override
    public String getErrorMessage() {
        return exceptionEnum.getErrorMessage();
    }

    @Override
    public Integer getErrorStatus() {
        return exceptionEnum.getErrorStatus();
    }

    @Override
    public CommonError setErrorMessage(String errorMessage) {
        exceptionEnum.setErrorMessage(errorMessage);
        return this;
    }
}
